using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;

namespace TS.Commons
{
    public static class CryptographyHelper
    {
        /// <summary>
        /// Hashes the password.
        /// </summary>
        /// <param name="password">The password.</param>
        /// <returns></returns>
        public static string HashPassword(string password)
        {
            var shaM = new SHA256Managed();
            var hash = new StringBuilder();
            var result = shaM.ComputeHash(Encoding.ASCII.GetBytes(password), 0,
                                              Encoding.ASCII.GetByteCount(password));
            foreach (var bit in result)
            {
                hash.Append(bit.ToString("x2", CultureInfo.CurrentCulture));
            }
            
            return hash.ToString();
        }
    }

    public static class CommonUtility
    {
        /// <summary>
        /// Checks the number.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns></returns>
        public static bool CheckNumber(string input)
        {
            Int64 rs;
            return Int64.TryParse(input, out rs);
        }
    }
}